#include	<stdio.h>
#include	<stdlib.h>
#include	<math.h>
#include	<string.h>
#include	"Uigp/igp.h"
#include	"ImageType/ImageType.h"
#include	"ImageType/ImageTool.h"
#include	"Ucamera/Pt2dType.h"
#include	"InterpolaionLib/Interpolation.h"
#include	"InterpolaionLib/Vornoi/VrLine.h"
#include    "InterpolaionLib/Vornoi/VrCell.h"



static void		read_command_line(int argc, char *argv[],
				  int *k, 
				  char *imageFile, char *outFile );


int
main( int argc, char **argv )
{
char	inFile[256],	outFile[256],	file[256];
pt2dA_type	*apt;
int	k;

	read_command_line( argc, argv, &k, inFile, outFile );

	if( pt2dA_read_from_file( &apt, inFile)< 0 )
		gpError( "interpolationCA", "Reading  %s  failed" );

	vrCell_type	vc;

	vrCell_line( apt, k, &vc );


	//vrCell_order( &vc );
	//filter on voronoi Cell
	//vrCell_filter( &vc);


	gpFilename_force_extension( outFile, ".ctr", file );
	vrCell_write( &vc, file  );

	return( 1 );
}



static char *Usage = 
"Usage: ImagePyramid    [-K#]       imageFile  outFile";



static void	
read_command_line(int argc, char *argv[],
				  int *K,
				  char *inFile, char *outFile )
{
	int     k;

	k = 1;

	*K = 0;
	if (k < argc && gp_strnicmp(argv[k], "-K", 2) == 0  ){
		sscanf( argv[k]+2, "%d", K );
		k++;
	}

	if (k < argc) {
		sprintf( inFile, "%s", argv[k]);
		k++;
	}
	else	error("read_command_line", Usage);
	
	if (k < argc) {
		sprintf( outFile, "%s", argv[k]);
		k++;
	}
	else	error("read_command_line", Usage);

}
